﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QuanLyKhachSan.DTO;

namespace QuanLyKhachSan
{
    public partial class frmQuanLyKhachSan : Form
    {
        public frmQuanLyKhachSan()
        {
            InitializeComponent();
        }
        
        //bien luu kiem tra dangNhap thanh cong
        private bool dangNhap = true;
        //luu nhanVien Dang nhap
        private NguoiDungDTO nhanVien;

        public NguoiDungDTO NhanVien
        {
            get { return nhanVien; }
            set { nhanVien = value; }
        }
       
        private void frmQuanLyKhachSan_Load(object sender, EventArgs e)
        {

            this.tsTenDangNhap.Visible = false;

            frmDangNhap frm = new frmDangNhap();
            frm.ShowDialog();
            if (frm.DangNhapThanhCong)
            {
                QuanLyLoaiPhong.Visible = true;
                LapDanhMucPhong.Visible = true;
                QuanLyLoaiKhachHang.Visible = true;
                báoCáoToolStripMenuItem.Visible = true;
                HeThong.Visible = true;
                QuanLyTaiKhoan.Visible = true ;

                //lay thong tin dang nhap
                this.nhanVien = frm.NhanVienDangNhap;

                tsTenDangNhap.Visible = true;
                // tsTenDangNhap.Enabled = false;
                string chucDanh = "";
                if (nhanVien.LoaiNguoiDung == 0)// la nguoi quan ly
                {
                    chucDanh = "Quản Lý: ";
                }
                else//la le tan
                    chucDanh = "Lễ Tân: ";
                tsTenDangNhap.Text = chucDanh + nhanVien.TenDangNhap;


                //xet nhan vien la LE TAN thi an 1 so chuc nang

                if (nhanVien.LoaiNguoiDung == 1)//la LE TAN
                {
                    QuanLyLoaiPhong.Visible = false;
                    LapDanhMucPhong.Visible = false;
                    QuanLyLoaiKhachHang.Visible = false;
                    báoCáoToolStripMenuItem.Visible = false;
                    HeThong.Visible = false;
                    QuanLyTaiKhoan.Visible = false;
                }                
            }
            else
            {
                dangNhap = false;
                this.Close();
            }
            
        }

        private void Thoat_Click(object sender, EventArgs e)
        {
            //this.Close();
            // MessageBox.Show("Bạn có chắc chắc muốn thoát?");
            DialogResult result = MessageBox.Show("Ban chac chan muon thoat?", "Thong Bao", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                //this.taiKhoanDangNhap = "";
                this.nhanVien = new NguoiDungDTO();
                //dong cac form dang mo
                int length = this.MdiChildren.Length;
                for (int i = length - 1; i >= 0; i--)
                {
                    this.MdiChildren[i].Close();
                }

                this.frmQuanLyKhachSan_Load(sender, e);

                
            }
        }

        private void LapDanhMucPhong_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmLapDanhMucPhong frm = new frmLapDanhMucPhong();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

        private void LapPhieuThuePhong_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmLapPhieuThuePhong frm = new frmLapPhieuThuePhong();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

        private void QuanLyLoaiPhong_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmQuanLyLoaiPhong frm = new frmQuanLyLoaiPhong();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

        private void QuanLyKhachHang_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmQuanLyKhachHang frm = new frmQuanLyKhachHang();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }
        private void QuanLyLoaiKhachHang_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmQuanLyLoaiKhachHang frm = new frmQuanLyLoaiKhachHang();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }
        private void LapHoaDon_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmLapHoaDon frm = new frmLapHoaDon();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

        private void TimKiemTheoPhong_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmTraCuuPhong frm = new frmTraCuuPhong();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }


        private void DoanhThuTheoLoaiPhong_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmBaoCaoDoanhThuTheoLoaiPhong frm = new frmBaoCaoDoanhThuTheoLoaiPhong();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

        private void DoanhThuTheoMatDoSuDungPhong_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmBaoCaoMatDoSuDungPhong frm = new frmBaoCaoMatDoSuDungPhong();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

        private void ThayDoiCacQuiDinh_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmThayDoiQuiDinh frm = new frmThayDoiQuiDinh();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

        private void QuanLyTaiKhoan_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }
           
            frmQuanLyTaiKhoan frm = new frmQuanLyTaiKhoan();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
            
        }

        private void CapNhatThongTinTaiKhoan_Click(object sender, EventArgs e)
        {
            //dong tat ca cac form khac dang mo
            int length = this.MdiChildren.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                this.MdiChildren[i].Close();
            }

            frmCapNhatThongTinTaiKhoan frm = new frmCapNhatThongTinTaiKhoan();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Tag = nhanVien;
            frm.Show();
        }

        
        private void HDQuanLyLoaiPhong_Click(object sender, EventArgs e)
        {
            frmHDQuanLyLoaiPhong frm = new frmHDQuanLyLoaiPhong();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

        private void HDQuanLyKhachHang_Click(object sender, EventArgs e)
        {
            frmHDQuanLyKhachHang frm = new frmHDQuanLyKhachHang();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

        private void HDQuanLyTaiKhoan_Click(object sender, EventArgs e)
        {
            frmHDQuanLyTaiKhoan frm = new frmHDQuanLyTaiKhoan();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }

       
        private void HDQuanLyLoaiKhachHang_Click(object sender, EventArgs e)
        {
            frmHDQuanLyLoaiKhachHang frm = new frmHDQuanLyLoaiKhachHang();
            frm.MdiParent = this;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.MaximizeBox = false;
            frm.Show();
        }
        private void frmQuanLyKhachSan_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (dangNhap == true )
            {
                DialogResult kq = MessageBox.Show("Ban co muon thoat khoi chuong trinh QUAN LY KHACH SAN hay khong?", "Thong Bao", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (kq == DialogResult.No)
                {
                    e.Cancel = true;
                }
                    
            }
           
        }

        private void hdToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.nhanVien.LoaiNguoiDung == 0)//la admin
            {

                Help.ShowHelp(this, "..\\..\\HDAdmin.chm");
            }
            else
                Help.ShowHelp(this, "..\\..\\HDLeTan.chm");
        }
       
    }
}